function n_files=convert_all_n(dir_name1,dir_name2,file_name);
%dir_name1='D:\tadpole project\From Debie\stesting_exist';
%dir_name2='D:\tadpole project\From Debie\stesting processed';
%file_name= name of brain file to be straightened
% n_files shows how many swc files have been converted
lst_swc=dir(dir_name1);
disp(lst_swc);
%s1 contains the number of files. File 1 is '.' aka current directory and file 2 is '..' aka parent directory
[s1,s2,s3]=size(lst_swc);
disp(s1);
disp(s2);
disp(s3);
n_files=0;
%So if the directory is not empty then process the files
if (s1>2)
  for i=1:s1-2
    %b1=qq(i).name
    %k=0;
    % Starting at first real file see if the file extension is .swc
    %k=strfind(lst_swc(i+2).name,'.swc');
    %disp(l);
    %disp(strcmp(lst_swc(i+2).name, file_name));
    
    %now we pass in correct file name to avoid issue with multiple runs on the same file
    iscorrectfile = strcmp(lst_swc(i+2).name, file_name);
    if (iscorrectfile), 
      % File to read will be current file
      name_r=[dir_name1,'\',lst_swc(i+2).name];
      % File to write to will be new file with same name in output dir (with 's.swc' appended)
      name_w=[dir_name2,'\',lst_swc(i+2).name(1:end-4),'s.swc'];
      fid_r = fopen(name_r,'r');
     % fid_w = fopen(name_w,'a');
      i=0;
      while feof(fid_r) == 0
       
        str = fgets(fid_r);
        k1=0;
        % Collect all comments in all_com file
        k1=strmatch('#',str);
        if k1>0
             i=i+1;
             all_com(i,1:length(str))=str;
             clear str
             %fprintf(fid_w,str);
        end;
      end;
      % Perform straightening
      [b,status]=strbody1(name_r);
      if (status~=0)
         display('BODY STRAIGHTENING:There are no ventral edge. A new file was not created');
         display('Old file was not changed: File name:  ');
         display(name_r);
         fclose('all');
         clear b; 
         status=1;
      else
         %fid_w = fopen(name_w,'at');
        %display(fid_w);
         fid_w = fopen(name_w,'wt');
         strqq=date;
         fprintf(fid_w,['# Straightened using convert_n.m   ' strqq,' \n']);
         for qq=1:i
           fprintf(fid_w,all_com(qq,:));
           fprintf(fid_w,'\n');
         end;
         [s3,s4]=size(b);   
         for j=1:s3
          %str2(1:100)=0;
         % str2=[num2str(b(j,1)),'   ',num2str(b(j,2)),'   ',num2str(b(j,3)),'   ',num2str(b(j,4)),'   ',num2str(b(j,5)),'   ',num2str(b(j,6)),'   ',num2str(b(j,7))];
          
         %str2=[num2str(b(j,1)),'   ',num2str(b(j,2)),'   ',num2str(b(j,3)),'   ',num2str(b(j,4)),'   ',num2str(b(j,5)),'   ',num2str(b(j,6)),'   ',num2str(b(j,7))];

        % fprintf(fid_w,'%s\n',str2);%          fprintf(fid_w,'%s\n',str2);%,'%s \n');%'%9.1f   %9.1f   %9.1f   %9.1f   %9.1f   %9.1f  %9.1f');
                 %fprintf(fid_w,' %6d  %6d  %10.2f %10.2f %10.2f %8.2f %6d\n',b(j,1:7));%
                 fprintf(fid_w,'%6d\t%6d\t%10.2f\t%10.2f\t%10.2f\t%8.2f\t%6d\n',b(j,1:7));%
         end;
         fclose('all');
         clear b;
         n_files=n_files+1; 
         %break;
      end;
    end;
  end;
else
    n_files=0;  
    display (' Empty directory!');
 end;
